package cn.tedu.egweibo5.base.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author Justin Parker
 * @author 2024/8/14 22:26
 * @version 1.0
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {

    @ApiModelProperty(value = "状态码")
    private int state;
    @ApiModelProperty(value = "状态信息")
    private String message;
    @ApiModelProperty(value = "响应数据")
    private Object data;

    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    public JsonResult(StatusCode statusCode,Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }



    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPEARTION_SUCCESS,data);
    }

    public static JsonResult ok() {
        return JsonResult.ok(null);
    }

    public static JsonResult fail(Object data){
        return new JsonResult(StatusCode.OPEARTION_FAILED,data);
    }

    public static JsonResult fail(){
        return JsonResult.fail(null);
    }
}
